package org.example.erp.controller;


import org.example.erp.domain.Workstation;
import org.example.erp.service.impl.WorkstationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class WorkstaionConfig {
    @Autowired
   private WorkstationServiceImpl workstationService;


    @GetMapping("/workstation/find")
    public DataResult find(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
                           @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                           @RequestParam (required = false)String workstationCode,
                           @RequestParam (required = false)String workstationName,
                           @RequestParam (required = false)String workshopCode,
                           @RequestParam (required = false)String processCode){
        return DataResult.success (workstationService.find(currentPage,pageSize,workstationCode,workstationName,workshopCode,processCode));
    }




    @PostMapping("/workstation/insert")
    public DataResult insert(@RequestBody Workstation workstation){
        System.out.println("添加");
        workstationService.save(workstation);
        return DataResult.success();

    }

    @PutMapping("/workstation/update")
    public DataResult update(@RequestBody Workstation workstation){
        boolean b = workstationService.updateById(workstation);
        if (b) {
        return DataResult.success("成功");
        }else{
            return DataResult.error("更新失败");
        }
    }


    @DeleteMapping("/workstation/delete")
    public DataResult delete(@RequestBody List<Integer> logIds){
        workstationService.removeByIds(logIds);
        return DataResult.success();
    }
}
